import json
class KeyHandler:
	def __init__(self,keyfile):
		self.key = None;
		with open(keyfile,"r") as f:
			content = f.read()
			try:
				self.key = json.loads(content)
			except Exception as e:
				print "Error while attempting to parse JSON response: %s" % e
				print "Content :\n%r" % content
		self.keyfile = keyfile
	def save(self):
		if self.key is None:
			return
		with open(self.keyfile, "w") as f:
			content = json.dumps(self.key)
			f.write(content)

if __name__ == "__main__":
	kh = KeyHandler("keys")
	print kh.key
	kh.key["nonce"]=18517
	kh.save()

